package com.example.mydy.model;

import android.content.Context;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Date;
import java.util.ArrayList;

public class RewardTask {
    // 进度状态常量
    public static final int STATUS_IN_PROGRESS = 0;  // 进行中
    public static final int STATUS_UNDER_REVIEW = 1; // 审核中
    public static final int STATUS_COMPLETED = 2;    // 已完成
    public static final int STATUS_REJECTED = 3;     // 已拒绝
    
    // 非序列化字段，不会发送到服务器
    private transient Context context;
    
    @SerializedName("id")
    private int id;
    
    @SerializedName("title")
    private String title;
    
    @SerializedName("description")
    private String description;
    
    @SerializedName("reward")
    private double reward;
    
    @SerializedName("status")
    private String status;
    
    @SerializedName("taken")
    private boolean taken;
    
    @SerializedName("createdAt")
    private String createdAt;
    
    @SerializedName("deadline")
    private String deadline;
    
    @SerializedName("tags")
    private List<String> tags;
    
    @SerializedName("remainingOrders")
    private int remainingOrders;
    
    @SerializedName("earnedPeople")
    private int earnedPeople;
    
    @SerializedName("username")
    private String username;
    
    @SerializedName("imageUrl")
    private String imageUrl;
    
    @SerializedName("category")
    private String category;
    
    @SerializedName("progressStatus")
    private int progressStatus = STATUS_IN_PROGRESS; // 默认为进行中
    
    @SerializedName("submissionContent")
    private String submissionContent; // 提交内容
    
    @SerializedName("submissionTime")
    private String submissionTime; // 提交时间
    
    @SerializedName("reviewComment")
    private String reviewComment; // 审核评语
    
    @SerializedName("reviewTime")
    private String reviewTime; // 审核时间
    
    // 新属性
    @SerializedName("isHot")
    private boolean isHot;
    
    @SerializedName("isNew")
    private boolean isNew;
    
    @SerializedName("createTime")
    private String createTime;
    
    // Getters and Setters
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public double getReward() {
        return reward;
    }
    
    public void setReward(double reward) {
        this.reward = reward;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public boolean isTaken() {
        return taken;
    }
    
    public void setTaken(boolean taken) {
        this.taken = taken;
    }
    
    public String getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }
    
    public String getDeadline() {
        return deadline;
    }
    
    public void setDeadline(String deadline) {
        this.deadline = deadline;
    }

    public Date getDeadlineAsDate() {
        // 转换字符串日期为Date对象
        try {
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.parse(deadline);
        } catch (Exception e) {
            return new Date(); // 返回当前日期作为默认值
        }
    }
    
    public List<String> getTags() {
        return tags;
    }
    
    public void setTags(List<String> tags) {
        this.tags = tags;
    }
    
    public int getRemainingOrders() {
        return remainingOrders;
    }
    
    public void setRemainingOrders(int remainingOrders) {
        this.remainingOrders = remainingOrders;
    }
    
    public int getEarnedPeople() {
        return earnedPeople;
    }
    
    public void setEarnedPeople(int earnedPeople) {
        this.earnedPeople = earnedPeople;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getUserName() {
        return username; // 使用username字段
    }
    
    public String getImageUrl() {
        return imageUrl;
    }
    
    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }
    
    public String getCategory() {
        // 如果未设置分类，返回一个默认值
        if (tags != null && !tags.isEmpty()) {
            return tags.get(0); // 使用第一个标签作为分类
        }
        return "其他"; // 默认分类
    }
    
    public void setCategory(String category) {
        if (tags == null) {
            tags = new ArrayList<>();
        }
        if (!tags.isEmpty()) {
            tags.set(0, category);
        } else {
            tags.add(category);
        }
    }
    
    public void setTotalOrders(int totalOrders) {
        int completedOrders = this.earnedPeople;
        this.remainingOrders = totalOrders - completedOrders;
    }
    
    public int getTotalOrders() {
        return this.remainingOrders + this.earnedPeople;
    }
    
    // 新增的Getters and Setters
    public int getProgressStatus() {
        return progressStatus;
    }
    
    public void setProgressStatus(int progressStatus) {
        this.progressStatus = progressStatus;
    }
    
    public String getSubmissionContent() {
        return submissionContent;
    }
    
    public void setSubmissionContent(String submissionContent) {
        this.submissionContent = submissionContent;
    }
    
    public String getSubmissionTime() {
        return submissionTime;
    }
    
    public void setSubmissionTime(String submissionTime) {
        this.submissionTime = submissionTime;
    }
    
    public String getReviewComment() {
        return reviewComment;
    }
    
    public void setReviewComment(String reviewComment) {
        this.reviewComment = reviewComment;
    }
    
    public String getReviewTime() {
        return reviewTime;
    }
    
    public void setReviewTime(String reviewTime) {
        this.reviewTime = reviewTime;
    }
    
    public boolean isHot() {
        return isHot;
    }
    
    public void setHot(boolean hot) {
        isHot = hot;
    }
    
    public boolean isNew() {
        return isNew;
    }
    
    public void setNew(boolean aNew) {
        isNew = aNew;
    }
    
    public String getCreateTime() {
        // 如果createTime为空，使用createdAt
        return createTime != null ? createTime : createdAt;
    }
    
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    
    public boolean isCompleted() {
        return progressStatus == STATUS_COMPLETED;
    }
    
    /**
     * 获取进度状态的文本描述
     * @return 状态描述
     */
    public String getProgressStatusText() {
        switch (progressStatus) {
            case STATUS_IN_PROGRESS:
                return "进行中";
            case STATUS_UNDER_REVIEW:
                return "审核中";
            case STATUS_COMPLETED:
                return "已完成";
            case STATUS_REJECTED:
                return "已拒绝";
            default:
                return "未知状态";
        }
    }
} 